package lia.org.model;

import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;


//@JsonDeserialize(using = CarJson.class)
public class Filter  implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -2094944429404412100L;
	private String property;
	private String value;

	public Filter(String property, String value) {
		super();
		this.property = property;
		this.value = value;
	}
	
	public Filter(String json) {
		super();
		ObjectMapper mapper = new ObjectMapper();  
		try {
			if (json != null)
			{
				
					
				Filter filter = 	mapper.readValue(
						json.substring(1, json.length()-1), 
						new TypeReference<Filter>() {});				
			
				this.property = filter.getProperty();
				this.value = filter.getValue();				
			}else
			{
				this.property = null;
				this.value = null;
			}
		
		} catch (JsonParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Filter() {
		super();
		// TODO Auto-generated constructor stub
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((property == null) ? 0 : property.hashCode());
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Filter other = (Filter) obj;
		if (property == null) {
			if (other.property != null)
				return false;
		} else if (!property.equals(other.property))
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}
	
	

}
